<?php
    include "sitedef.php";
    include "fct/Equipement.php";
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
        <LINK rel=stylesheet type="text/css" href="style.css">
        <style type="text/css">
            <?php
                foreach($crit as $cols)
                {
                    echo ".".$cols.",";
                }
                echo ".emplacement{font-weight:bold;}"
            ?>
        </style>
    </head>
    <body>
        <script type="text/javascript" src="affichage.js"></script>
        <form action="index.php" method="POST" name="nbr" id="nbr">
            <select name="nbr_crit" onchange="document.getElementById('nbr').submit();">
                <?php
                for($i=0;$i<7;$i++)
                {
                ?>
                <option value="<?php echo $i;?>" <?php if(isset($_POST['nbr_crit']) && $_POST['nbr_crit']==$i){ echo "selected";}?>><?php echo $i+1;?></option>
                <?php
                }
                ?>
            </select>
        </form>
        <form action="index.php" method="POST" onsubmit="document.getElementById('nbr').submit();">
            <span>
                <label>Argent Total Disponible : </label><input type="text" name="limite" value="<?php if(isset($_POST['limite'])){ echo $_POST['limite'];}?>"/>
                <br/>
                <label>Retirer les objets du march&eacute; Gold : </label><input type="checkbox" name="gold" <?php if(isset($_POST['gold'])){ echo "checked";}?>>
                <br/>
            </span>
            <span>
                <?php
                    if(!isset($_POST['nbr_crit']))
                    {
                        $nbr_crit = 0;
                    }
                    else
                    {
                        $nbr_crit = $_POST['nbr_crit'];
                    }
                    if ($nbr_crit<=7)
                    {
                        for($crit_aff=0;$crit_aff<=$nbr_crit;$crit_aff++)
                        {
                ?>
                            <select name="crit[]">
                                <option value=""></option>
                                <option value="cbt" <?php if(isset($_POST['crit'][$crit_aff]) && $_POST['crit'][$crit_aff]=="cbt"){ echo "selected";}?>>COMBAT</option>
                                <option value="forc" <?php if(isset($_POST['crit'][$crit_aff]) && $_POST['crit'][$crit_aff]=="forc"){ echo "selected";}?>>FORCE</option>
                                <option value="fpf" <?php if(isset($_POST['crit'][$crit_aff]) && $_POST['crit'][$crit_aff]=="fpf"){ echo "selected";}?>>FPF</option>
                                <option value="dbat" <?php if(isset($_POST['crit'][$crit_aff]) && $_POST['crit'][$crit_aff]=="dbat"){ echo "selected";}?>>DEGAT BAT</option>
                                <option value="def" <?php if(isset($_POST['crit'][$crit_aff]) && $_POST['crit'][$crit_aff]=="def"){ echo "selected";}?>>DEFENSE</option>
                                <option value="reg" <?php if(isset($_POST['crit'][$crit_aff]) && $_POST['crit'][$crit_aff]=="reg"){ echo "selected";}?>>REGENERATION</option>
                                <option value="vit" <?php if(isset($_POST['crit'][$crit_aff]) && $_POST['crit'][$crit_aff]=="vit"){ echo "selected";}?>>VITESSE</option>
                            </select>
                <?php
                        }
                    }
                ?>
            </span>
            <span><input type="submit" value="OK"></span>
            <input type="hidden" name="nbr_crit" value="<?php echo $nbr_crit;?>">
        </form>
        <table border="0" cellpadding="2" cellspacing="1">
                <tr><td>Choix</td><td>Emplacement</td><td>Nom</td><td>Prix</td><td>Combat</td><td>Force</td><td>Fatigue</td><td>Degats Bat.</td><td>Defense</td><td>Regeneration</td><td>Vitesse</td></tr>
                <?php
                //var_dump($_POST['limite']!=0);
                if(!isset($_POST['crit']))
                    $equip = getAllEquipement();
                elseif($_POST['limite']==0)
                    if(isset($_POST['gold']))
                        $equip = getBestEquipement($_POST['crit'],0);
                    else
                        $equip = getBestEquipement($_POST['crit']);
                else
                    if(isset($_POST['gold']))
                        $equip = getBestEquipement($_POST['crit'],0,1,$_POST['limite']);
                    else
                        $equip = getBestEquipement($_POST['crit'],1,1,$_POST['limite']);

                foreach($equip as $emplacement => $l_equip)
                {
                    foreach($l_equip as $item)
                    {
                ?>
                        <tr class="<?php echo $emplacement;?>" id="<?php echo $emplacement."_".$item['id'];?>"><td><input type="checkbox" onchange="chx_change('<?php echo $emplacement."_".$item['id'];?>');" value=""></td><td class="emplacement"><?php echo $emplacement;?></td><td class="nom"><?php echo $item['nom'];?></td><td class="prix"><?php echo $item['prix'];?></td><td class="cbt"><?php echo $item['cbt'];?></td><td class="forc"><?php echo $item['forc'];?></td><td class="fpf"><?php echo $item['fpf'];?></td><td class="dbat"><?php echo $item['dbat'];?></td><td class="def"><?php echo $item['def'];?></td><td class="reg"><?php echo $item['reg'];?></td><td class="vit"><?php echo $item['vit'];?></td></tr>
                <?php
                    }
                }
                ?>
                <tr id="total"><td class="emplacement" colspan="3">Total :</td><td class="prix" id="tot_prix"></td><td class="cbt" id="tot_cbt"></td><td class="forc" id="tot_forc"></td><td class="fpf" id="tot_fpf"></td><td class="dbat" id="tot_dbat"></td><td class="def" id="tot_def"></td><td class="reg" id="tot_reg"></td><td class="vit" id="tot_vit"></td><td class="gold" id="tot_gold"></td></tr>
        </table>
    </body>
</html>